package com.ocom.emqx.controller;


import com.ocom.common.constant.EmqxUrl;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.common.utils.ThreadTaskUtils;
import com.ocom.emqx.client.PayoperFeignService;
import com.ocom.emqx.handle.MqttSendClient;
import com.ocom.emqx.service.impl.HnQrCodeMachineServiceImpl;
import com.ocom.emqx.timer.UserRunnableTask;
import com.ocom.emqx.vo.QrCodePayingVo;
import com.ocom.redis.util.RedisUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
public class NongMaoController {

    @Resource
    private RedisUtil redisUtil;

    @Autowired
    MqttSendClient mqttSendClient;

    @Autowired
    private PayoperFeignService payoperFeignService;


    public Logger log = LoggerFactory.getLogger(NongMaoController.class);

    @PostMapping(EmqxUrl.URL_nmTimerQuery)
    public Result timerQuery(@RequestBody QrCodePayingVo qrCodePayingVo) {


        //支付中的处理
        redisUtil.zAdd("mqtt:orderPaying", qrCodePayingVo, System.currentTimeMillis());

        ThreadTaskUtils.run(new UserRunnableTask(qrCodePayingVo, redisUtil, mqttSendClient, payoperFeignService, log));
        log.info("Http插入定时查询 【{}】【{}】【{}】", qrCodePayingVo.getMachNo(), qrCodePayingVo.getTradeNo(), qrCodePayingVo);
        return ResultUtil.success();
    }
}
